package sz.szsmk.citizencard.mvp.dzsmkpresenter;

import sz.szsmk.citizencard.model.network.bean.response.GetCodeResponse;
import sz.szsmk.citizencard.model.network.dzbean.req.UserInfoUpdateRequest;
import sz.szsmk.citizencard.model.network.dzbean.res.User;
import sz.szsmk.citizencard.mvp.PersonInfoEditMvpView;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.smkretrofit.NetworkDateSource;
import sz.szsmk.citizencard.util.ObjectSignatureUtil;

import javax.inject.Inject;

import rx.functions.Action1;

/**
 * Created by chensf on 17/10/4.
 */

public class PersonInfoEditPresenter extends PersonInfoQueryPresenter<PersonInfoEditMvpView>{

    @Inject
    NetworkDateSource mNetworkDateSource;

    @Inject
    public PersonInfoEditPresenter(){
        getComponent().inject(this);
    }




    public void updatePersonInfo(User user){
        checkViewAttached();
        UserInfoUpdateRequest userInfoUpdateRequest = new UserInfoUpdateRequest();
        userInfoUpdateRequest.setDegree(user.getDegree());
        userInfoUpdateRequest.setEmail(user.getEmail());
        userInfoUpdateRequest.setNickName(user.getNickName());
        userInfoUpdateRequest.setPersonalSignature(user.getPersonalSignature());
        userInfoUpdateRequest.setGender(user.getGender());
        userInfoUpdateRequest.setStarSign(user.getStarSign());
        ObjectSignatureUtil.signatureRequest(userInfoUpdateRequest);
        mNetworkDateSource.updateUserInfo(userInfoUpdateRequest, new Action1<GetCodeResponse>() {
            @Override
            public void call(GetCodeResponse getCodeResponse) {
                String code = getCodeResponse.getCode();
                if (code!=null&&code.equals("0000")){
                    getMvpView().onUpdatePersonInfoSuccess();
                }
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });

    }

}
